import { Map } from 'immutable';

import * as actionTypes from './constants';

const defaultState = Map({
  playList: [
    {
      "name": "有何不可",
      "id": 167876,
      "pst": 0,
      "t": 0,
      "ar": [
        {
          "id": 5771,
          "name": "许嵩",
          "tns": [],
          "alias": []
        }
      ],
      "alia": [],
      "pop": 100,
      "st": 0,
      "rt": "600902000007916021",
      "fee": 8,
      "v": 49,
      "crbt": null,
      "cf": "",
      "al": {
        "id": 16953,
        "name": "自定义",
        "picUrl": "https://p1.music.126.net/Md3RLH0fe2a_3dMDnfqoQg==/18590542604286213.jpg",
        "tns": [],
        "pic_str": "18590542604286213",
        "pic": 18590542604286212
      },
      "dt": 241840,
      "h": {
        "br": 320000,
        "fid": 0,
        "size": 9675799,
        "vd": -21099
      },
      "m": {
        "br": 192000,
        "fid": 0,
        "size": 5805497,
        "vd": -18400
      },
      "l": {
        "br": 128000,
        "fid": 0,
        "size": 3870346,
        "vd": -16900
      },
      "a": null,
      "cd": "1",
      "no": 3,
      "rtUrl": null,
      "ftype": 0,
      "rtUrls": [],
      "djId": 0,
      "copyright": 2,
      "s_id": 0,
      "mark": 8192,
      "originCoverType": 0,
      "single": 0,
      "noCopyrightRcmd": null,
      "mv": 0,
      "mst": 9,
      "cp": 14026,
      "rtype": 0,
      "rurl": null,
      "publishTime": 1231516800000,
      "playing": false
    },
    {
      "name": "雅俗共赏",
      "id": 411214279,
      "pst": 0,
      "t": 0,
      "ar": [
        {
          "id": 5771,
          "name": "许嵩",
          "tns": [],
          "alias": []
        }
      ],
      "alia": [],
      "pop": 100,
      "st": 0,
      "rt": null,
      "fee": 8,
      "v": 31,
      "crbt": null,
      "cf": "",
      "al": {
        "id": 34749138,
        "name": "青年晚报",
        "picUrl": "https://p1.music.126.net/Wcs2dbukFx3TUWkRuxVCpw==/3431575794705764.jpg",
        "tns": [],
        "pic": 3431575794705764
      },
      "dt": 249621,
      "h": {
        "br": 320000,
        "fid": 0,
        "size": 9987177,
        "vd": -22200
      },
      "m": {
        "br": 192000,
        "fid": 0,
        "size": 5992323,
        "vd": -19600
      },
      "l": {
        "br": 128000,
        "fid": 0,
        "size": 3994896,
        "vd": -17800
      },
      "a": null,
      "cd": "1",
      "no": 2,
      "rtUrl": null,
      "ftype": 0,
      "rtUrls": [],
      "djId": 0,
      "copyright": 0,
      "s_id": 0,
      "mark": 8192,
      "originCoverType": 0,
      "single": 0,
      "noCopyrightRcmd": null,
      "mv": 5302271,
      "rtype": 0,
      "rurl": null,
      "mst": 9,
      "cp": 14026,
      "publishTime": 1461723397683,
      "playing": false
    },
    {
      "name": "须尽欢",
      "id": 1465053754,
      "pst": 0,
      "t": 0,
      "ar": [
        {
          "id": 189955,
          "name": "蔡翊昇",
          "tns": [],
          "alias": []
        }
      ],
      "alia": [],
      "pop": 95,
      "st": 0,
      "rt": "",
      "fee": 8,
      "v": 3,
      "crbt": null,
      "cf": "",
      "al": {
        "id": 92888006,
        "name": "须尽欢",
        "picUrl": "https://p2.music.126.net/6hbspsO3-NVIFOIA37ijjw==/109951165162665196.jpg",
        "tns": [],
        "pic_str": "109951165162665196",
        "pic": 109951165162665200
      },
      "dt": 195000,
      "h": {
        "br": 320002,
        "fid": 0,
        "size": 7802925,
        "vd": -47478
      },
      "m": {
        "br": 192002,
        "fid": 0,
        "size": 4681773,
        "vd": -44949
      },
      "l": {
        "br": 128002,
        "fid": 0,
        "size": 3121197,
        "vd": -43399
      },
      "a": null,
      "cd": "01",
      "no": 1,
      "rtUrl": null,
      "ftype": 0,
      "rtUrls": [],
      "djId": 0,
      "copyright": 0,
      "s_id": 0,
      "mark": 8192,
      "originCoverType": 1,
      "originSongSimpleData": null,
      "tagPicList": null,
      "resourceState": true,
      "version": 3,
      "songJumpInfo": null,
      "single": 0,
      "noCopyrightRcmd": null,
      "rtype": 0,
      "rurl": null,
      "mst": 9,
      "cp": 1416917,
      "mv": 0,
      "publishTime": 0
    },
    {
      "name": "白自在",
      "id": 29822035,
      "pst": 0,
      "t": 0,
      "ar": [
        {
          "id": 6460,
          "name": "张学友",
          "tns": [],
          "alias": []
        }
      ],
      "alia": [],
      "pop": 95,
      "st": 0,
      "rt": null,
      "fee": 1,
      "v": 41,
      "crbt": null,
      "cf": "",
      "al": {
        "id": 3084625,
        "name": "醒着做梦",
        "picUrl": "https://p1.music.126.net/XeBV6fMffdsPfI8H-I_64A==/6649846326157603.jpg",
        "tns": [],
        "pic": 6649846326157603
      },
      "dt": 218000,
      "h": {
        "br": 320000,
        "fid": 0,
        "size": 8727095,
        "vd": -33577
      },
      "m": {
        "br": 192000,
        "fid": 0,
        "size": 5236300,
        "vd": -33577
      },
      "l": {
        "br": 128000,
        "fid": 0,
        "size": 3490903,
        "vd": -33577
      },
      "a": null,
      "cd": "1",
      "no": 9,
      "rtUrl": null,
      "ftype": 0,
      "rtUrls": [],
      "djId": 0,
      "copyright": 1,
      "s_id": 0,
      "mark": 270336,
      "originCoverType": 0,
      "originSongSimpleData": null,
      "tagPicList": null,
      "resourceState": true,
      "version": 41,
      "songJumpInfo": null,
      "single": 0,
      "noCopyrightRcmd": null,
      "mst": 9,
      "cp": 7003,
      "rtype": 0,
      "rurl": null,
      "mv": 0,
      "publishTime": 1388505600000
    },
    {
      "name": "删了吧",
      "id": 1891469546,
      "pst": 0,
      "t": 0,
      "ar": [
        {
          "id": 49937403,
          "name": "烟(许佳豪)",
          "tns": [],
          "alias": []
        }
      ],
      "alia": [
        "要不你还是把我删了吧"
      ],
      "pop": 100,
      "st": 0,
      "rt": "",
      "fee": 8,
      "v": 5,
      "crbt": null,
      "cf": "",
      "al": {
        "id": 135521932,
        "name": "删了吧",
        "picUrl": "https://p2.music.126.net/nNg4YjkcK1AwCX1FrN8VOQ==/109951166578333625.jpg",
        "tns": [],
        "pic_str": "109951166578333625",
        "pic": 109951166578333630
      },
      "dt": 204955,
      "h": {
        "br": 320000,
        "fid": 0,
        "size": 8200403,
        "vd": -26816
      },
      "m": {
        "br": 192000,
        "fid": 0,
        "size": 4920259,
        "vd": -24206
      },
      "l": {
        "br": 128000,
        "fid": 0,
        "size": 3280187,
        "vd": -22486
      },
      "a": null,
      "cd": "01",
      "no": 1,
      "rtUrl": null,
      "ftype": 0,
      "rtUrls": [],
      "djId": 0,
      "copyright": 0,
      "s_id": 0,
      "mark": 8192,
      "originCoverType": 0,
      "originSongSimpleData": null,
      "tagPicList": null,
      "resourceState": true,
      "version": 5,
      "songJumpInfo": null,
      "single": 0,
      "noCopyrightRcmd": null,
      "rtype": 0,
      "rurl": null,
      "mst": 9,
      "cp": 0,
      "mv": 0,
      "publishTime": 1636128000000
    },
    {
      "name": "你的姑娘",
      "id": 1356499052,
      "pst": 0,
      "t": 0,
      "ar": [
        {
          "id": 12429072,
          "name": "隔壁老樊",
          "tns": [],
          "alias": []
        }
      ],
      "alia": [],
      "pop": 100,
      "st": 0,
      "rt": "",
      "fee": 8,
      "v": 80,
      "crbt": null,
      "cf": "",
      "al": {
        "id": 75019098,
        "name": "我曾",
        "picUrl": "https://p2.music.126.net/gNbAlXamNjhR2j3aOukNhg==/109951164232796511.jpg",
        "tns": [],
        "pic_str": "109951164232796511",
        "pic": 109951164232796510
      },
      "dt": 248124,
      "h": {
        "br": 320000,
        "fid": 0,
        "size": 9927619,
        "vd": -17600
      },
      "m": {
        "br": 192000,
        "fid": 0,
        "size": 5956589,
        "vd": -14900
      },
      "l": {
        "br": 128000,
        "fid": 0,
        "size": 3971074,
        "vd": -13300
      },
      "a": null,
      "cd": "01",
      "no": 5,
      "rtUrl": null,
      "ftype": 0,
      "rtUrls": [],
      "djId": 0,
      "copyright": 0,
      "s_id": 0,
      "mark": 0,
      "originCoverType": 1,
      "originSongSimpleData": null,
      "tagPicList": null,
      "resourceState": true,
      "version": 80,
      "songJumpInfo": null,
      "single": 0,
      "noCopyrightRcmd": null,
      "mv": 10864930,
      "mst": 9,
      "cp": 0,
      "rtype": 0,
      "rurl": null,
      "publishTime": 0
    }
  ],
  currentSongIndex: 0, // 当前播放歌曲的索引
  currentSong: {}, // 当前播放的歌曲信息
  sequence: 0, // 0 循环 1 随机 2 单曲
  lyricList: [], // 转化 后的 歌词数组
  currentLyricIndex: 0 // 某一行歌词的索引
})

function reducer(state = defaultState, action) {
  switch (action.type) {
    case actionTypes.CHANGE_CURRENT_SONG:
      return state.set("currentSong", action.currentSong);
    case actionTypes.CHANGE_PLAY_LIST:
      return state.set("playList", action.playList);
    case actionTypes.CHANGE_CURRENT_SONG_INDEX:
      return state.set("currentSongIndex", action.index);
    // 改变播放的状态 顺序 ？ 单曲 ？ 
    case actionTypes.CHANGE_SEQUENCE:
      return state.set("sequence", action.sequence);
    case actionTypes.CHANGE_LYRIC_LIST:
      return state.set("lyricList", action.lyricList);
    case actionTypes.CHANGE_CURRENT_LYRIC_INDEX:
      return state.set("currentLyricIndex", action.index);
    case actionTypes.DELETE_LIEST:
      state.set("currentSongIndex", 0);
      state.set("currentSong", {});
      state.set("sequence", 0);
      state.set("lyricList", []);
      state.set("currentLyricIndex", 0);
      return state.set("playList", []);

    default:
      return state;
  }
}

export default reducer;